﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ChinaDynastyTours.Controls
{
    public class SalePriceCtrl
    {
        public static DataSet teamPriceDs = new DataSet();
        private static DataTable teamPriceDt = new DataTable();
        private static DataTable teamAverageDt = new DataTable();

        static SalePriceCtrl()
        {
            teamPriceDt.Columns.Add("dayID", typeof(int));
            teamPriceDt.Columns.Add("CityName",typeof(string));

            teamPriceDt.Columns.Add("ComplexCost", typeof(decimal));
            teamPriceDt.Columns.Add("MealCost", typeof(decimal));
            teamPriceDt.Columns.Add("OverKMCost", typeof(decimal));
            teamPriceDt.Columns.Add("RoomCost", typeof(decimal));
            teamPriceDt.Columns.Add("TicketsCost", typeof(decimal));
            teamPriceDt.Columns.Add("CitiesTrafficCost", typeof(decimal));

            teamAverageDt.Columns.Add("TourgroupID", typeof(string));
            teamAverageDt.Columns.Add("Population", typeof(int));
            teamAverageDt.Columns.Add("AverageCost", typeof(decimal));
            teamAverageDt.Columns.Add("ProfitRate", typeof(decimal));
            teamAverageDt.Columns.Add("AveragePrice", typeof(decimal));
            teamAverageDt.Columns.Add("Currency", typeof(string));
            teamAverageDt.Columns.Add("ExchangeRate", typeof(decimal));
            teamAverageDt.Columns.Add("CurrencyAmount", typeof(decimal));

            teamPriceDt.TableName = "teamPriceDt";
            teamAverageDt.TableName = "teamAverageDt";
            teamPriceDs.Tables.Add(teamPriceDt);
            teamPriceDs.Tables.Add(teamAverageDt);
        }  

        public static DataSet GetAllData()
        {

            if (teamPriceDs != null)
                return teamPriceDs;
            else
                return null;
        }

        /// <summary>
        /// .cst文件路径及文件名称
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static bool LoadAllData(string tourgroupId)
        {
            try
            {
                DataSet tmpDs = TeamGroupCtrl.GetSaleDataSet(tourgroupId);
                foreach (DataRow dr in tmpDs.Tables[0].Rows)
                {
                    teamPriceDs.Tables["teamPriceDt"].ImportRow(dr);
                }
                foreach (DataRow dr in tmpDs.Tables[1].Rows)
                {
                    teamPriceDs.Tables["teamAverageDt"].ImportRow(dr);
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static void ClearAllData()
        {
            teamPriceDs.Clear();
        }
    }
}
